/**
 * Created by wangjian on 2017/10/20.
 */

app.component('mForm', {
    transclude: true,
    bindings: {
        formSave: '&',
        formBack: '&',
        isSaveShow: "@",
        isBackShow: "@",
        invalid: "=?"
    },
    controller: function ($scope, $element, $attrs) {
        var ctrl = this;
        ctrl.saveShow = false;
        ctrl.backShow = false;
        if (ctrl.isSaveShow == "true" || ctrl.isSaveShow == true) {
            ctrl.saveShow = true;
        }
        if (ctrl.isBackShow == "true" || ctrl.isBackShow == true) {
            ctrl.backShow = true;
        }
        ctrl.save = function () {
            ctrl.formSave({});
        }
        ctrl.back = function () {
            ctrl.formBack({});
        }

        if (ctrl.invalid == undefined) {
            ctrl.invalid = true;
        }

        $("#formid").on('submit', function (e) {
            if ($('#2').froalaEditor('core.isEmpty')) {
                e.preventDefault();
                $('#2').froalaEditor('events.focus');
                ctrl.invalid = true;
                return false;
            }
            ctrl.formSave({});
        })

        $scope.$on('submit', function (event, data) {
            angular.element("#myform").click();
        })
    },
    templateUrl: getTemplateUrl('matrix/component/tpl/mForm.html')
})
app.component('mFormLable', {
    transclude: true,
    bindings: {
        title: '@',
        method: '@',
        noBorder: '@'
    },
    controller: function () {
    },
    templateUrl: getTemplateUrl('matrix/component/tpl/mFormLable.html')
}).component('mFormLine', {
    transclude: true,
    require: {
        formCtrl: '^mForm'
    },
    bindings: {
        label: '@',
        remind: '<'
    },
    controller: function () {
    },
    templateUrl: getTemplateUrl('matrix/component/tpl/mFormLine.html')
});